<?php


namespace app\home\model;


use app\admin\model\NewsCommunicationDetail;
use think\Db;

class NewsCommunication extends Base
{
    protected $insert = [
        'create_time' => NOW_TIME,
    ];

    /**
     * @param $permission 权限类别
     * @param $userId   用户id
     * @param int $status   状态，0待分发，1轮阅中，2已归档
     * @param int $leng 数据长度
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getList($permission,$userId,$status = 0,$leng = 0)
    {
        $map = [
            'b.permission' => $permission,
            'b.userid' => $userId,
            'b.status' => $status
        ];
        $list = Db::table('zm_news_communication')->alias('a')
            ->join('zm_news_communication_detail b','a.id = b.communication_id','LEFT')
            ->where($map)
            ->field('b.id,a.title,a.type,a.create_time,b.permission,b.userid,b.communication_id,b.status')
            ->order('b.create_time desc')
            ->limit($leng,8)
            ->select();
        int_to_string($list,['type' => [1 => "行政", 2 => "党建", 3 => "工会", 4 => "其它" ]]);
        return $list;
    }
}